#include "../include/settingswidget.h"
#include "../include/config.h"
#include "../include/gameservice.h"
#include <QMessageBox>
#include <QDateTime>

SettingsWidget::SettingsWidget(AuthService *authService, QWidget *parent)
    : QWidget(parent)
    , m_authService(authService)
    , m_settings(new QSettings(this))
    , m_primaryColor("#4A90E2")
    , m_secondaryColor("#7ED321")
    , m_backgroundColor("#2C3E50")
    , m_textColor("#ECF0F1")
    , m_errorColor("#E74C3C")
    , m_successColor("#27AE60")
{
    setupUI();
    applyStyles();
    loadSettings();
    updateUserInfo();
}

SettingsWidget::~SettingsWidget()
{
    // QSettings是通过parent管理的，会自动清理
    // 其他UI组件也是通过Qt的父子关系自动管理
}

void SettingsWidget::setupUI()
{
    m_mainLayout = new QVBoxLayout(this);
    m_mainLayout->setSpacing(25);
    m_mainLayout->setContentsMargins(30, 30, 30, 30);

    // 页面标题区域
    QWidget *headerWidget = new QWidget();
    QHBoxLayout *headerLayout = new QHBoxLayout(headerWidget);
    headerLayout->setContentsMargins(0, 0, 0, 0);

    QLabel *titleLabel = new QLabel("⚙️ 应用设置", this);
    titleLabel->setObjectName("pageTitle");
    headerLayout->addWidget(titleLabel);

    headerLayout->addStretch();

    // 添加版本信息
    QLabel *versionInfo = new QLabel(QString("版本 %1").arg(Config::getAppVersion()), this);
    versionInfo->setObjectName("versionInfo");
    headerLayout->addWidget(versionInfo);

    m_mainLayout->addWidget(headerWidget);

    // 选项卡
    m_tabWidget = new QTabWidget(this);
    m_tabWidget->setObjectName("settingsTabWidget");
    m_tabWidget->setTabPosition(QTabWidget::North);
    m_tabWidget->setMovable(false);
    m_tabWidget->setTabsClosable(false);

    setupGeneralTab();
    setupGameTab();
    setupAccountTab();
    setupAboutTab();

    m_mainLayout->addWidget(m_tabWidget);

    // 按钮区域
    QHBoxLayout *buttonLayout = new QHBoxLayout();
    buttonLayout->addStretch();

    m_resetButton = new QPushButton("重置默认", this);
    m_resetButton->setObjectName("secondaryButton");
    connect(m_resetButton, &QPushButton::clicked, this, &SettingsWidget::onResetClicked);
    buttonLayout->addWidget(m_resetButton);

    m_saveButton = new QPushButton("保存设置", this);
    m_saveButton->setObjectName("primaryButton");
    connect(m_saveButton, &QPushButton::clicked, this, &SettingsWidget::onSaveClicked);
    buttonLayout->addWidget(m_saveButton);

    m_mainLayout->addLayout(buttonLayout);
}

void SettingsWidget::setupGeneralTab()
{
    m_generalTab = new QWidget();
    QVBoxLayout *generalLayout = new QVBoxLayout(m_generalTab);
    generalLayout->setSpacing(15);

    // 外观设置
    QGroupBox *appearanceGroup = new QGroupBox("外观设置", this);
    appearanceGroup->setObjectName("settingsGroup");
    QFormLayout *appearanceLayout = new QFormLayout(appearanceGroup);

    m_themeCombo = new QComboBox(this);
    m_themeCombo->setObjectName("settingsCombo");
    m_themeCombo->addItem("深色主题", "dark");
    m_themeCombo->addItem("浅色主题", "light");
    m_themeCombo->addItem("自动", "auto");
    connect(m_themeCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
            this, &SettingsWidget::onThemeChanged);
    appearanceLayout->addRow("主题:", m_themeCombo);

    m_languageCombo = new QComboBox(this);
    m_languageCombo->setObjectName("settingsCombo");
    m_languageCombo->addItem("简体中文", "zh_CN");
    m_languageCombo->addItem("English", "en_US");
    connect(m_languageCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
            this, &SettingsWidget::onLanguageChanged);
    appearanceLayout->addRow("语言:", m_languageCombo);

    generalLayout->addWidget(appearanceGroup);

    // 启动设置
    QGroupBox *startupGroup = new QGroupBox("启动设置", this);
    startupGroup->setObjectName("settingsGroup");
    QVBoxLayout *startupLayout = new QVBoxLayout(startupGroup);

    m_autoStartCheck = new QCheckBox("开机自动启动", this);
    m_autoStartCheck->setObjectName("settingsCheck");
    startupLayout->addWidget(m_autoStartCheck);

    m_minimizeToTrayCheck = new QCheckBox("启动时最小化到系统托盘", this);
    m_minimizeToTrayCheck->setObjectName("settingsCheck");
    startupLayout->addWidget(m_minimizeToTrayCheck);

    generalLayout->addWidget(startupGroup);

    // 通知设置
    QGroupBox *notificationGroup = new QGroupBox("通知设置", this);
    notificationGroup->setObjectName("settingsGroup");
    QVBoxLayout *notificationLayout = new QVBoxLayout(notificationGroup);

    m_notificationCheck = new QCheckBox("启用桌面通知", this);
    m_notificationCheck->setObjectName("settingsCheck");
    connect(m_notificationCheck, &QCheckBox::toggled, this, &SettingsWidget::onNotificationToggled);
    notificationLayout->addWidget(m_notificationCheck);

    generalLayout->addWidget(notificationGroup);

    generalLayout->addStretch();
    m_tabWidget->addTab(m_generalTab, "🎨 通用设置");
}

void SettingsWidget::setupGameTab()
{
    m_gameTab = new QWidget();
    QVBoxLayout *gameLayout = new QVBoxLayout(m_gameTab);
    gameLayout->setSpacing(15);

    // 默认游戏设置
    QGroupBox *defaultsGroup = new QGroupBox("默认设置", this);
    defaultsGroup->setObjectName("settingsGroup");
    QFormLayout *defaultsLayout = new QFormLayout(defaultsGroup);

    m_defaultGameTypeCombo = new QComboBox(this);
    m_defaultGameTypeCombo->setObjectName("settingsCombo");
    m_defaultGameTypeCombo->addItem("无偏好", "");
    for (const QString &gameType : GameService::getSupportedGameTypes()) {
        m_defaultGameTypeCombo->addItem(gameType, gameType);
    }
    defaultsLayout->addRow("默认游戏类型:", m_defaultGameTypeCombo);

    m_defaultRegionCombo = new QComboBox(this);
    m_defaultRegionCombo->setObjectName("settingsCombo");
    m_defaultRegionCombo->addItem("无偏好", "");
    m_defaultRegionCombo->addItem("亚洲", "asia");
    m_defaultRegionCombo->addItem("欧洲", "europe");
    m_defaultRegionCombo->addItem("美洲", "america");
    defaultsLayout->addRow("默认地区:", m_defaultRegionCombo);

    m_serverPreferenceCombo = new QComboBox(this);
    m_serverPreferenceCombo->setObjectName("settingsCombo");
    for (const QString &preference : GameService::getServerPreferences()) {
        m_serverPreferenceCombo->addItem(preference, preference);
    }
    defaultsLayout->addRow("服务器偏好:", m_serverPreferenceCombo);

    gameLayout->addWidget(defaultsGroup);

    // 刷新设置
    QGroupBox *refreshGroup = new QGroupBox("刷新设置", this);
    refreshGroup->setObjectName("settingsGroup");
    QFormLayout *refreshLayout = new QFormLayout(refreshGroup);

    m_autoRefreshCheck = new QCheckBox("启用自动刷新", this);
    m_autoRefreshCheck->setObjectName("settingsCheck");
    connect(m_autoRefreshCheck, &QCheckBox::toggled, this, &SettingsWidget::onAutoRefreshToggled);
    refreshLayout->addRow("", m_autoRefreshCheck);

    m_refreshIntervalSpin = new QSpinBox(this);
    m_refreshIntervalSpin->setObjectName("settingsSpin");
    m_refreshIntervalSpin->setRange(10, 300);
    m_refreshIntervalSpin->setSuffix(" 秒");
    m_refreshIntervalSpin->setValue(30);
    connect(m_refreshIntervalSpin, QOverload<int>::of(&QSpinBox::valueChanged),
            this, &SettingsWidget::onRefreshIntervalChanged);
    refreshLayout->addRow("刷新间隔:", m_refreshIntervalSpin);

    gameLayout->addWidget(refreshGroup);

    // 连接设置
    QGroupBox *connectionGroup = new QGroupBox("连接设置", this);
    connectionGroup->setObjectName("settingsGroup");
    QFormLayout *connectionLayout = new QFormLayout(connectionGroup);

    QHBoxLayout *pingLayout = new QHBoxLayout();
    m_maxPingSlider = new QSlider(Qt::Horizontal, this);
    m_maxPingSlider->setObjectName("settingsSlider");
    m_maxPingSlider->setRange(50, 500);
    m_maxPingSlider->setValue(150);
    connect(m_maxPingSlider, &QSlider::valueChanged, [this](int value) {
        m_maxPingLabel->setText(QString("%1ms").arg(value));
    });
    pingLayout->addWidget(m_maxPingSlider);

    m_maxPingLabel = new QLabel("150ms", this);
    m_maxPingLabel->setObjectName("settingsLabel");
    m_maxPingLabel->setMinimumWidth(50);
    pingLayout->addWidget(m_maxPingLabel);

    connectionLayout->addRow("最大延迟:", pingLayout);

    gameLayout->addWidget(connectionGroup);

    gameLayout->addStretch();
    m_tabWidget->addTab(m_gameTab, "🎮 游戏设置");
}

void SettingsWidget::setupAccountTab()
{
    m_accountTab = new QWidget();
    QVBoxLayout *accountLayout = new QVBoxLayout(m_accountTab);
    accountLayout->setSpacing(15);

    // 账户信息
    QGroupBox *infoGroup = new QGroupBox("账户信息", this);
    infoGroup->setObjectName("settingsGroup");
    QFormLayout *infoLayout = new QFormLayout(infoGroup);

    m_usernameLabel = new QLabel(this);
    m_usernameLabel->setObjectName("infoLabel");
    infoLayout->addRow("用户名:", m_usernameLabel);

    m_emailLabel = new QLabel(this);
    m_emailLabel->setObjectName("infoLabel");
    infoLayout->addRow("邮箱:", m_emailLabel);

    m_lastLoginLabel = new QLabel(this);
    m_lastLoginLabel->setObjectName("infoLabel");
    infoLayout->addRow("最后登录:", m_lastLoginLabel);

    m_loginCountLabel = new QLabel(this);
    m_loginCountLabel->setObjectName("infoLabel");
    infoLayout->addRow("登录次数:", m_loginCountLabel);

    accountLayout->addWidget(infoGroup);

    // 账户操作
    QGroupBox *actionsGroup = new QGroupBox("账户操作", this);
    actionsGroup->setObjectName("settingsGroup");
    QVBoxLayout *actionsLayout = new QVBoxLayout(actionsGroup);

    m_changePasswordButton = new QPushButton("修改密码", this);
    m_changePasswordButton->setObjectName("secondaryButton");
    connect(m_changePasswordButton, &QPushButton::clicked, this, &SettingsWidget::onChangePasswordClicked);
    actionsLayout->addWidget(m_changePasswordButton);

    m_logoutAllButton = new QPushButton("登出所有设备", this);
    m_logoutAllButton->setObjectName("warningButton");
    connect(m_logoutAllButton, &QPushButton::clicked, this, &SettingsWidget::onLogoutAllDevicesClicked);
    actionsLayout->addWidget(m_logoutAllButton);

    accountLayout->addWidget(actionsGroup);

    accountLayout->addStretch();
    m_tabWidget->addTab(m_accountTab, "👤 账户管理");
}

void SettingsWidget::setupAboutTab()
{
    m_aboutTab = new QWidget();
    QVBoxLayout *aboutLayout = new QVBoxLayout(m_aboutTab);
    aboutLayout->setSpacing(20);

    // 应用信息
    QGroupBox *appGroup = new QGroupBox("应用信息", this);
    appGroup->setObjectName("settingsGroup");
    QVBoxLayout *appLayout = new QVBoxLayout(appGroup);

    m_appNameLabel = new QLabel(Config::getAppName(), this);
    m_appNameLabel->setAlignment(Qt::AlignCenter);
    m_appNameLabel->setObjectName("appNameLabel");
    appLayout->addWidget(m_appNameLabel);

    m_versionLabel = new QLabel(QString("版本 %1").arg(Config::getAppVersion()), this);
    m_versionLabel->setAlignment(Qt::AlignCenter);
    m_versionLabel->setObjectName("versionLabel");
    appLayout->addWidget(m_versionLabel);

    m_buildDateLabel = new QLabel(QString("构建日期: %1").arg(__DATE__), this);
    m_buildDateLabel->setAlignment(Qt::AlignCenter);
    m_buildDateLabel->setObjectName("buildDateLabel");
    appLayout->addWidget(m_buildDateLabel);

    aboutLayout->addWidget(appGroup);

    // 关于文本
    m_aboutText = new QTextEdit(this);
    m_aboutText->setObjectName("aboutText");
    m_aboutText->setReadOnly(true);
    m_aboutText->setMaximumHeight(200);
    m_aboutText->setHtml(
        "<h3>关于游戏客户端</h3>"
        "<p>这是一个基于Qt开发的现代化游戏客户端，支持多种游戏类型和服务器连接。</p>"
        "<p><b>主要功能:</b></p>"
        "<ul>"
        "<li>用户注册和登录</li>"
        "<li>游戏服务器浏览</li>"
        "<li>实时服务器状态监控</li>"
        "<li>多游戏类型支持</li>"
        "<li>现代化用户界面</li>"
        "</ul>"
        "<p><b>技术栈:</b> Qt 6, C++, 微服务架构</p>"
        "<p><b>开发团队:</b> 29108</p>"
    );

    aboutLayout->addWidget(m_aboutText);

    aboutLayout->addStretch();
    m_tabWidget->addTab(m_aboutTab, "ℹ️ 关于应用");
}

void SettingsWidget::onSaveClicked()
{
    saveSettings();
    emit settingsChanged();

    QMessageBox::information(this, "提示", "设置已保存");
}

void SettingsWidget::onResetClicked()
{
    int ret = QMessageBox::question(this, "确认",
        "确定要重置所有设置到默认值吗？",
        QMessageBox::Yes | QMessageBox::No);

    if (ret == QMessageBox::Yes) {
        resetToDefaults();
        QMessageBox::information(this, "提示", "设置已重置为默认值");
    }
}

void SettingsWidget::onChangePasswordClicked()
{
    QMessageBox::information(this, "提示", "修改密码功能将在后续版本中提供");
}

void SettingsWidget::onLogoutAllDevicesClicked()
{
    int ret = QMessageBox::question(this, "确认",
        "确定要登出所有设备吗？这将使您在其他设备上的登录失效。",
        QMessageBox::Yes | QMessageBox::No);

    if (ret == QMessageBox::Yes) {
        m_authService->logout(true);
        QMessageBox::information(this, "提示", "已登出所有设备");
    }
}

void SettingsWidget::onThemeChanged()
{
    QString theme = m_themeCombo->currentData().toString();
    emit themeChanged(theme);
}

void SettingsWidget::onLanguageChanged()
{
    QString language = m_languageCombo->currentData().toString();
    QMessageBox::information(this, "提示", "语言设置将在重启应用后生效");
}

void SettingsWidget::onAutoRefreshToggled(bool enabled)
{
    m_refreshIntervalSpin->setEnabled(enabled);
}

void SettingsWidget::onRefreshIntervalChanged(int seconds)
{
    // 这里可以发送信号通知其他组件更新刷新间隔
}

void SettingsWidget::onNotificationToggled(bool enabled)
{
    // 这里可以启用或禁用通知功能
}

void SettingsWidget::loadSettings()
{
    // 通用设置
    QString theme = m_settings->value("theme", "dark").toString();
    int themeIndex = m_themeCombo->findData(theme);
    if (themeIndex >= 0) {
        m_themeCombo->setCurrentIndex(themeIndex);
    }

    QString language = m_settings->value("language", "zh_CN").toString();
    int languageIndex = m_languageCombo->findData(language);
    if (languageIndex >= 0) {
        m_languageCombo->setCurrentIndex(languageIndex);
    }

    m_autoStartCheck->setChecked(m_settings->value("auto_start", false).toBool());
    m_minimizeToTrayCheck->setChecked(m_settings->value("minimize_to_tray", false).toBool());
    m_notificationCheck->setChecked(m_settings->value("notifications", true).toBool());

    // 游戏设置
    QString defaultGameType = m_settings->value("default_game_type", "").toString();
    int gameTypeIndex = m_defaultGameTypeCombo->findData(defaultGameType);
    if (gameTypeIndex >= 0) {
        m_defaultGameTypeCombo->setCurrentIndex(gameTypeIndex);
    }

    QString defaultRegion = m_settings->value("default_region", "asia").toString();
    int regionIndex = m_defaultRegionCombo->findData(defaultRegion);
    if (regionIndex >= 0) {
        m_defaultRegionCombo->setCurrentIndex(regionIndex);
    }

    QString serverPreference = m_settings->value("server_preference", "balanced").toString();
    int preferenceIndex = m_serverPreferenceCombo->findData(serverPreference);
    if (preferenceIndex >= 0) {
        m_serverPreferenceCombo->setCurrentIndex(preferenceIndex);
    }

    m_autoRefreshCheck->setChecked(m_settings->value("auto_refresh", true).toBool());
    m_refreshIntervalSpin->setValue(m_settings->value("refresh_interval", 30).toInt());
    m_refreshIntervalSpin->setEnabled(m_autoRefreshCheck->isChecked());

    int maxPing = m_settings->value("max_ping", 150).toInt();
    m_maxPingSlider->setValue(maxPing);
    m_maxPingLabel->setText(QString("%1ms").arg(maxPing));
}

void SettingsWidget::saveSettings()
{
    // 通用设置
    m_settings->setValue("theme", m_themeCombo->currentData());
    m_settings->setValue("language", m_languageCombo->currentData());
    m_settings->setValue("auto_start", m_autoStartCheck->isChecked());
    m_settings->setValue("minimize_to_tray", m_minimizeToTrayCheck->isChecked());
    m_settings->setValue("notifications", m_notificationCheck->isChecked());

    // 游戏设置
    m_settings->setValue("default_game_type", m_defaultGameTypeCombo->currentData());
    m_settings->setValue("default_region", m_defaultRegionCombo->currentData());
    m_settings->setValue("server_preference", m_serverPreferenceCombo->currentData());
    m_settings->setValue("auto_refresh", m_autoRefreshCheck->isChecked());
    m_settings->setValue("refresh_interval", m_refreshIntervalSpin->value());
    m_settings->setValue("max_ping", m_maxPingSlider->value());

    m_settings->sync();
}

void SettingsWidget::resetToDefaults()
{
    // 重置通用设置
    m_themeCombo->setCurrentIndex(m_themeCombo->findData("dark"));
    m_languageCombo->setCurrentIndex(m_languageCombo->findData("zh_CN"));
    m_autoStartCheck->setChecked(false);
    m_minimizeToTrayCheck->setChecked(false);
    m_notificationCheck->setChecked(true);

    // 重置游戏设置
    m_defaultGameTypeCombo->setCurrentIndex(0);
    m_defaultRegionCombo->setCurrentIndex(m_defaultRegionCombo->findData("asia"));
    m_serverPreferenceCombo->setCurrentIndex(m_serverPreferenceCombo->findData("balanced"));
    m_autoRefreshCheck->setChecked(true);
    m_refreshIntervalSpin->setValue(30);
    m_refreshIntervalSpin->setEnabled(true);
    m_maxPingSlider->setValue(150);
    m_maxPingLabel->setText("150ms");

    saveSettings();
}

void SettingsWidget::updateUserInfo()
{
    if (m_authService->isAuthenticated()) {
        AuthService::UserInfo userInfo = m_authService->getCurrentUser();
        m_usernameLabel->setText(userInfo.username);
        m_emailLabel->setText(userInfo.email);
        m_lastLoginLabel->setText(userInfo.lastLogin);
        m_loginCountLabel->setText(QString::number(userInfo.loginCount));
    } else {
        m_usernameLabel->setText("未登录");
        m_emailLabel->setText("未登录");
        m_lastLoginLabel->setText("未登录");
        m_loginCountLabel->setText("0");
    }
}

void SettingsWidget::applyStyles()
{
    setStyleSheet(QString(R"(
        QWidget {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 %1, stop:0.5 #34495E, stop:1 #2C3E50);
            color: %2;
            font-family: 'Microsoft YaHei', 'Segoe UI', Arial, sans-serif;
        }

        #pageTitle {
            font-size: 28px;
            font-weight: bold;
            color: %3;
            margin-bottom: 10px;
            /* 移除不支持的text-shadow属性 */
        }

        #versionInfo {
            font-size: 14px;
            color: #BDC3C7;
            background: rgba(52, 73, 94, 0.6);
            border: 1px solid rgba(74, 144, 226, 0.3);
            border-radius: 15px;
            padding: 8px 16px;
        }

        #settingsTabWidget {
            background-color: transparent;
            border: none;
        }

        #settingsTabWidget::pane {
            border: 2px solid rgba(74, 144, 226, 0.4);
            border-radius: 15px;
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 rgba(52, 73, 94, 0.9), stop:1 rgba(44, 62, 80, 0.9));
            margin-top: 15px;
        }

        #settingsTabWidget::tab-bar {
            alignment: center;
        }

        #settingsTabWidget QTabBar::tab {
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 rgba(44, 62, 80, 0.9), stop:1 rgba(52, 73, 94, 0.9));
            color: %2;
            border: 2px solid #34495E;
            border-bottom: none;
            border-top-left-radius: 12px;
            border-top-right-radius: 12px;
            padding: 15px 25px;
            margin-right: 3px;
            font-size: 14px;
            font-weight: 600;
            min-width: 120px;
        }

        #settingsTabWidget QTabBar::tab:selected {
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 %3, stop:1 #3498DB);
            color: white;
            border-color: %3;
            /* 移除不支持的text-shadow属性 */
        }

        #settingsTabWidget QTabBar::tab:hover:!selected {
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 rgba(74, 144, 226, 0.4), stop:1 rgba(52, 152, 219, 0.4));
            border-color: %3;
            color: white;
        }

        #settingsGroup {
            background-color: rgba(44, 62, 80, 0.6);
            border: 2px solid #34495E;
            border-radius: 8px;
            padding: 15px;
            margin: 10px 5px;
        }

        #settingsGroup::title {
            color: %3;
            font-size: 14px;
            font-weight: bold;
            padding: 0 10px;
        }

        #settingsCombo {
            background-color: rgba(44, 62, 80, 0.9);
            border: 2px solid #34495E;
            border-radius: 6px;
            padding: 8px 12px;
            font-size: 13px;
            color: %2;
            min-width: 120px;
        }

        #settingsCombo:focus {
            border-color: %3;
        }

        #settingsCombo::drop-down {
            border: none;
            background-color: transparent;
        }

        #settingsCombo::down-arrow {
            image: none;
            border-left: 5px solid transparent;
            border-right: 5px solid transparent;
            border-top: 5px solid %2;
            margin-right: 5px;
        }

        #settingsCombo QAbstractItemView {
            background-color: rgba(44, 62, 80, 0.95);
            border: 2px solid %3;
            border-radius: 6px;
            color: %2;
            selection-background-color: %3;
        }

        #settingsSpin {
            background-color: rgba(44, 62, 80, 0.9);
            border: 2px solid #34495E;
            border-radius: 6px;
            padding: 8px 12px;
            font-size: 13px;
            color: %2;
            min-width: 80px;
        }

        #settingsSpin:focus {
            border-color: %3;
        }

        #settingsCheck {
            color: %2;
            font-size: 13px;
            spacing: 8px;
        }

        #settingsCheck::indicator {
            width: 16px;
            height: 16px;
            border: 2px solid #34495E;
            border-radius: 3px;
            background-color: rgba(44, 62, 80, 0.9);
        }

        #settingsCheck::indicator:checked {
            background-color: %3;
            border-color: %3;
        }

        #settingsCheck::indicator:hover {
            border-color: %3;
        }

        #settingsSlider::groove:horizontal {
            border: 2px solid #34495E;
            height: 8px;
            background-color: rgba(44, 62, 80, 0.9);
            border-radius: 4px;
        }

        #settingsSlider::handle:horizontal {
            background-color: %3;
            border: 2px solid %3;
            width: 18px;
            margin: -5px 0;
            border-radius: 9px;
        }

        #settingsSlider::handle:horizontal:hover {
            background-color: #5DADE2;
            border-color: #5DADE2;
        }

        #settingsSlider::sub-page:horizontal {
            background-color: %3;
            border-radius: 4px;
        }

        #settingsLabel {
            color: %2;
            font-size: 13px;
            font-weight: 500;
        }

        #infoLabel {
            color: %3;
            font-size: 14px;
            font-weight: 500;
            background-color: rgba(44, 62, 80, 0.6);
            border: 1px solid #34495E;
            border-radius: 4px;
            padding: 8px 12px;
        }

        #appNameLabel {
            font-size: 20px;
            font-weight: bold;
            color: %3;
            margin: 10px 0;
        }

        #versionLabel {
            font-size: 14px;
            color: %2;
            margin: 5px 0;
        }

        #buildDateLabel {
            font-size: 12px;
            color: #BDC3C7;
            margin: 5px 0;
        }

        #aboutText {
            background-color: rgba(44, 62, 80, 0.9);
            border: 2px solid #34495E;
            border-radius: 6px;
            color: %2;
            font-size: 13px;
            padding: 10px;
        }

        #primaryButton {
            background-color: %3;
            color: white;
            border: none;
            border-radius: 6px;
            padding: 12px 24px;
            font-size: 14px;
            font-weight: bold;
            min-width: 100px;
        }

        #primaryButton:hover {
            background-color: #5DADE2;
        }

        #primaryButton:pressed {
            background-color: #3498DB;
        }

        #secondaryButton {
            background-color: rgba(44, 62, 80, 0.9);
            color: %2;
            border: 2px solid #34495E;
            border-radius: 6px;
            padding: 12px 24px;
            font-size: 14px;
            font-weight: bold;
            min-width: 100px;
        }

        #secondaryButton:hover {
            border-color: %3;
            color: %3;
        }

        #secondaryButton:pressed {
            background-color: rgba(74, 144, 226, 0.2);
        }

        #warningButton {
            background-color: %4;
            color: white;
            border: none;
            border-radius: 6px;
            padding: 12px 24px;
            font-size: 14px;
            font-weight: bold;
            min-width: 100px;
        }

        #warningButton:hover {
            background-color: #C0392B;
        }

        #warningButton:pressed {
            background-color: #A93226;
        }

        QFormLayout QLabel {
            color: %2;
            font-size: 13px;
            font-weight: 500;
        }
    )").arg(m_backgroundColor, m_textColor, m_primaryColor, m_errorColor));
}
